# coding=utf-8
import arcpy

aprx = arcpy.mp.ArcGISProject(r"D:\\Documents\\OneDrive\\毕业论文\\三省道路交通网\\三省道路交通网.aprx")
map = aprx.listMaps("地图")[0]
lyr = map.listLayers("路径")[0]
lyr1 = map.listLayers("起始点")[0]
print(lyr1)
rows1 = arcpy.SearchCursor(lyr1, '', '', '', 'ObjectID')
lyr2 = map.listLayers("目的地点")[0]
print(lyr2)
rows2 = arcpy.SearchCursor(lyr2, '', '', '', 'ObjectID')
lyr3 = map.listLayers("停靠点")[0]
lyr4 = map.listLayers("路径")[1]
lyr5 = map.listLayers("南昌都市圈道路网中心性路径")[0]
i=0
for row1 in rows1:
    i=i+1
    j=0
    lyr1.definitionQuery = "Name = " + "'" + row1.getValue("Name") + "'"
    for row2 in rows2:
        j=j+1
        lyr2.definitionQuery = "Name = " + "'" + row2.getValue("Name") + "'"
        arcpy.management.Append([lyr1, lyr2], lyr3, "NO_TEST")
        try:
            arcpy.na.Solve(in_network_analysis_layer=lyr, ignore_invalids="SKIP", terminate_on_solve_error="TERMINATE", simplification_tolerance="", overrides="")
            arcpy.management.Append(lyr4, lyr5, "NO_TEST")
            print(i,j)
        except Exception as e:
            print(str(e))
                
        arcpy.management.DeleteRows(lyr3)
del rows1,rows2
del aprx
